package com.app.controller;

import com.app.aop.has.HasApiLimit;
import com.app.aop.has.HasRedissonLock;
import com.app.aop.has.HasRole;
import com.app.domain.bo.DanMuBo;
import com.app.domain.page.Page;
import com.app.domain.vo.DanMuVo;
import com.app.framework.common.R;
import com.app.service.DanMuService;
import jakarta.annotation.Resource;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

/**
 * 弹幕控制器
 */
@RestController
@RequestMapping("/api/danmu")
public class DanMuController {

    @Resource
    private DanMuService danmuService;

    /**
     * 弹幕列表
     *
     * @param articleId 文章ID
     */
    @GetMapping("/list/{articleId}")
    public R<Page<DanMuVo>> lists(@PathVariable("articleId") Long articleId) {
        return R.ok(danmuService.lists(articleId));
    }

    /**
     * 添加弹幕
     *
     * @param bo 入参
     */
    @HasApiLimit()
    @HasRedissonLock("save_danmu")
    @PostMapping("/save")
    public R<?> saveOne(@RequestBody DanMuBo bo) {
        Assert.notNull(bo.getArticleId(), "文章ID不能为空");
        danmuService.saveOne(bo);
        return R.ok(null, "弹幕发送成功");
    }

    /**
     * 屏蔽弹幕
     *
     * @param danmuId 弹幕ID
     */
    @HasRole()
    @PostMapping("/shield/{danmuId}")
    public R<?> shield(@PathVariable("danmuId") Long danmuId) {
        danmuService.shield(danmuId);
        return R.ok(null, "弹幕屏蔽成功");
    }

}